package org.ns.summer.beans.anns;

import org.ns.summer.core.AnnotationUtils;

import java.io.File;

/**
 *
 */
public class ComponentScanUtils {
    /**
     *
     * @param configType 配置的class
     * @param prefixs    默认值
     * @return
     */
    public static String[] getComponentPackagePath(Class<?> configType, String[] prefixs) {
        ComponentScan componentScan = (ComponentScan)AnnotationUtils.getAnnotation(configType, ComponentScan.class);
        if (componentScan == null || componentScan.value().length == 0) {
            if (prefixs == null) {
                return new String[]{configType.getPackage().getName().replace(".", File.separator)};
            } else {
                return prefixs;
            }
        }
        String[] result = null;
        if (prefixs == null) {
            result = new String[componentScan.value().length + 1];
            result[0] = configType.getPackage().getName().replace(".", File.separator);
            System.arraycopy(componentScan.value(), 0, result, 1, componentScan.value().length);
        } else {
            result = new String[componentScan.value().length + prefixs.length];
            System.arraycopy(prefixs, 0, result, 0, prefixs.length);
            System.arraycopy(componentScan.value(), 0, result, prefixs.length, componentScan.value().length);
        }
        return result;
    }
}
